package com.example.myapplication1121

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.*
import androidx.compose.material3.*
import androidx.compose.runtime.*
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.unit.dp

class MainActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MaterialTheme {
                ArtGalleryApp()
            }
        }
    }
}

@Composable
fun ArtGalleryApp() {
    // 使用 Android 系统自带的图标进行测试
    val artworks = listOf(
        Artwork(android.R.drawable.ic_dialog_email, "Blue Rose and Flowers", "Owen Scott", 2021),
        Artwork(android.R.drawable.ic_dialog_info, "Mountain Landscape", "Emily Chen", 2020),
        Artwork(android.R.drawable.ic_dialog_alert, "Urban Dreams", "Marcus Johnson", 2019)
    )

    var currentIndex by remember { mutableStateOf(0) }

    Column(
        modifier = Modifier
            .fillMaxSize()
            .padding(16.dp),
        horizontalAlignment = Alignment.CenterHorizontally
    ) {
        Text(
            "Art Gallery",
            style = MaterialTheme.typography.headlineLarge,
            modifier = Modifier.padding(16.dp)
        )

        // 图片显示 - 添加边框和背景以便调试
        Box(
            modifier = Modifier
                .fillMaxWidth()
                .weight(1f)
                .background(MaterialTheme.colorScheme.surfaceVariant)
        ) {
            Image(
                painter = painterResource(id = artworks[currentIndex].imageRes),
                contentDescription = "Artwork image",
                modifier = Modifier
                    .fillMaxSize()
                    .padding(32.dp)
            )
        }

        Spacer(modifier = Modifier.height(16.dp))

        // 作品信息
        Text(
            artworks[currentIndex].title,
            style = MaterialTheme.typography.headlineSmall
        )
        Text(
            "${artworks[currentIndex].artist} (${artworks[currentIndex].year})",
            style = MaterialTheme.typography.bodyMedium
        )

        Spacer(modifier = Modifier.height(24.dp))

        // 导航按钮
        Row(
            modifier = Modifier.fillMaxWidth(),
            horizontalArrangement = Arrangement.SpaceEvenly
        ) {
            Button(onClick = {
                currentIndex = if (currentIndex == 0) artworks.size - 1 else currentIndex - 1
            }) {
                Text("Previous")
            }

            Button(onClick = {
                currentIndex = (currentIndex + 1) % artworks.size
            }) {
                Text("Next")
            }
        }

        // 页面指示
        Text(
            "${currentIndex + 1} of ${artworks.size}",
            modifier = Modifier.padding(8.dp)
        )
    }
}

data class Artwork(
    val imageRes: Int,
    val title: String,
    val artist: String,
    val year: Int
)